Ext.onReady(function() {
	Ext.Loader.setConfig({
		enabled : true
	});
	Ext.Loader.setPath('org.jks', '/view');
	Ext.Loader.setPath('Ext.ux', '/resources/ext/ux');

	Ext.define('NavItem', {
	    extend: 'Ext.data.Model',
	    fields: [
	        { name:'url', type:'string' },
	        { name:'cls', type:'string' }
	    ]
	});
	var data = [
		    	{url: 'workMgr/', cls: 'nav_item_task', selected:true},
		    	{url: 'infoQry/', cls: 'nav_item_info'},
		    	{url: 'wuziMgr/', cls: 'nav_item_goods'}
		    ];
	if(user.Username == 'admin')
	{
		data = [
		    	{url: 'sysMgr/', cls: 'nav_item_sysmgr', selected:true},
		    	{url: 'workMgr/', cls: 'nav_item_task'},
		    	{url: 'infoQry/', cls: 'nav_item_info'},
		    	{url: 'wuziMgr/', cls: 'nav_item_goods'}
		    ];
	}
	var navStore = Ext.create('Ext.data.Store', {
	    id:'NavStore',
	    model: 'NavItem',
	    data: data
	});
	var itemTpl = new Ext.XTemplate(
	    '<tpl for=".">',
	        '<div class="{cls}" style="width:90px;height:90px;">',
	        '</div>',
	    '</tpl>'
	);
	var navigation = Ext.create('Ext.view.View', {
		region: 'west',
		width: 100,
		margin: '5 5 5 20',
		store: navStore,
	    tpl: itemTpl,
	    overItemCls: 'over_nav_item',
	    selectedItemCls: 'pressed_nav_item',
	    itemSelector: 'div',
	    listeners:{
	    	itemclick : function(self, record, item, index, e, eOpts ){
	    		setTimeout(function(){
            		Ext.getCmp('main').load(record.get("url"));
            	}, 300);
	    	}
	    }
	});
	
	var iframe = Ext.create("Ext.ux.IFrame",{
		id: 'main',
		loader:{
			loadMask:true,
			scripts:true,
			autoLoad:false
		}
	});
	var contentPanel = Ext.create("Ext.container.Container",{
		region : 'center',
		margin: "0 20 0 0",
		layout: 'fit',
		items: [iframe]
	});
	setTimeout(function(){
		if(user.Username == 'admin')
		{
			Ext.getCmp('main').load("sysMgr/");
		}
		else
		{
			Ext.getCmp('main').load("workMgr/");			
		}
	}, 300);
	
	var footerPanel = Ext.create("Ext.container.Container",{
		region: 'south',
		margin: '5 0 0 0',
		items:[{
			xtype: 'component',
			style: 'text-align:center',
			html: '<div class="foot">国家电网公司 版权所有 CopyRight ©2015 State Grid Corporation of China</div>'
		}]
	});
	
	var topHtml = '<div class="top">'+
			'<div class="logo"></div>'+
			'<div class="welcome">'+
	    		'<div class="login" id="logined">欢迎您，<a id="uId"><i>' + user.Username + '</i></a>&nbsp;&nbsp;<a href="/logout">退出</a></div>'+
	    	'</div>'+
	    	'<div class="airplane"></div>'+
			'</div>';
	
	Ext.create('Ext.Viewport', {
		layout : 'border',
		minHeight: 600,
		minWidth:1100,
		autoScroll:true,
		cls: "blank",
		items : [ {
			xtype : 'container',
			id : 'header',
			region : 'north',
			margin: '0 0',
			style: 'background: url(view/images/topBg.jpg) center 0px no-repeat',
			html:topHtml,
			height : 160
		},  navigation, contentPanel,footerPanel],
		renderTo : Ext.getBody(),
		listeners:{
			afterrender: function(self){
				navigation.getSelectionModel().select(0);
			}
		}
	});
	
	
});